package com.test.common;

/**  
 * 存放分页相关数据的page类
 */  
public class Page {   
    
    private int pageNo = 1;   //页码，默认是第一页   
    private int pageSize = 10;//每页显示的记录数，默认是10   
    private long totalRow;    //总记录数   
    private long totalPage;   //总页数   
	private int pageStart;    //从第几条开始取
	private int pageEnd;      //取到第几条
	
	public int getPageNo() {   
       return pageNo;   
    }   
    
    public void setPageNo(int pageNo) {   
       this.pageNo = pageNo;   
    }   
    
    public int getPageSize() {   
       return pageSize;   
    }   
    
    public void setPageSize(int pageSize) {   
       this.pageSize = pageSize;   
    }   
    
    public long getTotalRow() {   
       return totalRow;   
    }   
    
    /**
     *  在设置总记录条数的时候
     *  设置总记录数、总页数、查询起始位置
     */
	public void setTotalRow(long totalRow) {
		this.totalRow = totalRow;
		long totalPage = totalRow / pageSize + ((totalRow % pageSize == 0) ? 0 : 1);
		this.setTotalPage(totalPage);
		this.pageStart = (this.pageNo - 1) * this.pageSize;
		this.pageEnd = this.pageNo * this.pageSize;
    }   
    
	public int getPageStart() {
		return pageStart;
	}

	public void setPageStart(int pageStart) {
		this.pageStart = pageStart;
	}

	public int getPageEnd() {
		return pageEnd;
	}

	public void setPageEnd(int pageEnd) {
		this.pageEnd = pageEnd;
	}

	public long getTotalPage() {   
       return totalPage;   
    }   
    
    public void setTotalPage(long totalPage) {   
       this.totalPage = totalPage;   
    } 
    
	@Override  
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Page [pageNo=").append(pageNo).append(", pageSize=").append(pageSize).append(", pageStart=")
				.append(pageStart).append(", pageEnd=").append(pageEnd).append(", totalPage=").append(totalPage)
				.append(", totalRow=").append(totalRow).append("]");
		return builder.toString();
	}  
    
}  
